package br.project.cdd.dao;

import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.ArrayList;
import br.project.cdd.bean.UfBean;

public class UfDAO extends Conexao {
	
	public UfDAO() throws ClassNotFoundException, SQLException 
	{
		super();		
	}
	
	public ArrayList<UfBean> selecionarTodasUfs()
	{
		ArrayList<UfBean> listUfs = new ArrayList<UfBean>();
		UfBean ufs = null;
		try
		{
			String sql = "SELECT UF, NOME, SIGLA FROM ESTADO";
			Statement stmt = conexao.createStatement();
			ResultSet consulta = stmt.executeQuery(sql);
			
			while (consulta.next())
			{
				ufs = new UfBean();				
				ufs.setIdUf(consulta.getInt(1));
				ufs.setNome(consulta.getString(2));
				ufs.setSigla(consulta.getString(3));
				
				listUfs.add(ufs);
			}
		}
		catch(SQLException sqlEx)
		{
			sqlEx.printStackTrace();
		}
		
		return listUfs;
	}
}
